<?php
namespace Admin\Controller;
use Think\Controller;
class UploadController extends BaseController {
	
    //内容编辑器图片上传方法
	public function uploade(){
    	$upload = new \Think\Upload();// 实例化上传类
		$upload->maxSize   =     3145728 ;// 设置附件上传大小
    	$upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
    	$upload->rootPath  =      './Uploads/Content/'; // 设置附件上传根目录
		$upload->saveName  =    'guid';
		$upload->autoSub   =    true;
		$upload->subName   =   array('date','Ymd');	
    	$info  =  $upload->upload();// 上传单个文件
    	if(!$info) {// 上传错误提示错误信息
        	$this->error($upload->getError());
    	}else{// 上传成功 获取上传文件信息
        foreach($info as $file){
            $url = './Uploads/Content/'.$file['savepath'].$file['savename'];
            $image = new \Think\Image(); 
            $image->open($url);
            $image->thumb(450, 450)->save('./Uploads/Content/thumb/'.$file['savename']);
            $imgurl = '/Uploads/Content/thumb/'.$file['savename'];
            $this->ajaxReturn($imgurl,'EVAL');
            }
        }
    }
    //相册图片上传方法
    public function uploadp(){
    	$upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize   =    3145728 ;// 设置附件上传大小
        $upload->exts      =    array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload->rootPath  =    './Uploads/Photo/'; // 设置附件上传根目录
        $upload->savePath  = 	'Thumb';
        $upload->saveName  = 	'guid';
        $upload->autoSub   =    true;
        $upload->subName   =    array('date','Ymd'); 
        $info  =  $upload->upload();// 上传单个文件
        if(!$info) {// 上传错误提示错误信息
            $this->error($upload->getError());
        }else{// 上传成功 获取上传文件信息
        foreach($info as $file){
            $url = './Uploads/Photo/'.$file['savepath'].$file['savename'];
            $image = new \Think\Image(); 
            $image->open($url);
            $image->thumb(450, 450)->save('./Uploads/Photo/thumb/'.$file['savename']);
            $imgurl['pic'] = '/Uploads/Photo/thumb/'.$file['savename'];
            $imgurl['name'] = $file['savename'];
            $this->ajaxReturn($imgurl);
            }
        }
    }
    //内容缩略图上传方法
    public function uploadt(){
        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize   =     3145728 ;// 设置附件上传大小
        $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload->rootPath  =      './Uploads/Content/'; // 设置附件上传根目录
        $upload->saveName = 'time';
        $upload->autoSub   =    true;
        $upload->subName   =   array('date','Ymd'); 
        $info  =  $upload->upload();// 上传单个文件
        if(!$info) {// 上传错误提示错误信息
            $this->error($upload->getError());
        }else{// 上传成功 获取上传文件信息
        foreach($info as $file){
            $url = './Uploads/Content/'.$file['savepath'].$file['savename'];
            $image = new \Think\Image(); 
            $image->open($url);
            $image->thumb(450, 450)->save('./Uploads/Content/thumb/'.$file['savename']);
            $imgurl['pic'] = '/Uploads/Content/thumb/'.$file['savename'];
            $imgurl['name'] = $file['savename'];
            $this->ajaxReturn($imgurl);
            }
        }
    }
    
} 